<template>
    <el-dialog
        :before-close="resetForm"
        :close-on-click-modal="false"
        :visible.sync="visible"
        append-to-body
        title="编辑菜单信息"
        width="560px"
    >
        <div class="edit_page_div">
            <el-form ref="form" :model="form" :rules="rules" :show-message="false" inline label-width="100px">
				<el-form-item label="父级ID" prop="parentsId">
					<el-input v-model="form.parentsId" style="width: 400px;"></el-input>
				</el-form-item>
                <el-form-item label="权限名称" prop="powerName">
                    <el-input v-model="form.powerName" style="width: 400px;"></el-input>
                </el-form-item>
				<el-form-item label="权限编号" prop="powerCode">
					<el-input v-model="form.powerCode" style="width: 400px;"></el-input>
				</el-form-item>
                <el-form-item label="权限路径" prop="powerPath">
                    <el-input v-model="form.powerPath" style="width: 400px;"></el-input>
                </el-form-item>
                <el-form-item label="实际路径" prop="actualPath">
                    <el-input v-model="form.actualPath" style="width: 400px;"></el-input>
                </el-form-item>
                <el-form-item label="显示顺序" prop="orderNum">
                    <el-input v-model="form.orderNum" style="width: 400px;"></el-input>
                </el-form-item>
                <el-form-item label="是否启用" prop="enableFlag">
                    <radios-option v-model="form.enableFlag"></radios-option>
                </el-form-item>
                <el-form-item label="显示样式" prop="showStyle" v-if="form.parentsId>0">
                    <el-input v-model="form.showStyle" style="width: 400px;"></el-input>
                </el-form-item>
            </el-form>
            <div class="edit_button">
                <el-button v-loading.fullscreen.lock="loading" type="primary" @click="submit">保 存</el-button>
                <el-button type="primary" @click="resetForm">取 消</el-button>
            </div>
        </div>
    </el-dialog>
</template>

<script>
import RadiosOption from "@/components/radio/radiosOption";
import SelectOption from "@/components/select/selectOption";

export default {
    name: "powerEdit",
    components: {RadiosOption, SelectOption},
    props: {
        visible: Boolean,
        id: Number,
    },
    data() {
        return {
            loading: false,
            showUpload: false,
            suffixes: '',
            form: {
                powerType: 1,
                parentsId: '',
                powerCode: '',
                powerName: '',
                powerPath: '',
                showStyle: '',
                actualPath: '',
                enableFlag: 1,
                orderNum: 1,
            },
            rules: {
                parentsId: [{required: true, message: '不能为空', trigger: 'change'}],
                powerCode: [{required: true, message: '不能为空', trigger: 'change'}],
                powerName: [{required: true, message: '不能为空', trigger: 'change'}],
                powerPath: [{required: true, message: '不能为空', trigger: 'change'}],
                actualPath: [{required: true, message: '不能为空', trigger: 'change'}],
                enableFlag: [{required: true, message: '不能为空', trigger: 'change'}],
            },
			programList: [],
        }
    },
    watch: {
        visible(newVal) {
            if (newVal) {
                if (this.id) {
                    this.getData();
                }
            }
        }
    },
    methods: {
        getData() {
            this.$axios.get("/CHILD_SYSTEM/systemPower/getOneEntity/" + this.id).then(res => {
                this.form = res.data;
            }).finally(() => {
                this.loading = false;
            })
        },
        uploadImg() {
            this.suffixes = ".jpg,.png,.gif";
            this.showUpload = true;
        },
        setFileList(data) {
            this.form.showStyle = data[0].filePath;
        },
        submit() {
            this.$refs.form.validate((valid) => {
                if (valid) {
                    if (this.form.parentsId == 0) {
                        alert(1)
                        this.form.showStyle = "demo/20221115/" + this.form.powerCode + ".jpg";
                    }
                    this.loading = true;
                    this.$axios.post("/CHILD_SYSTEM/systemPower/" + (this.id ? "update" : "insert"), this.form).then(res => {
                        this.resetForm();
                        this.$message.success(res.message);
                    }).finally(() => {
                        this.loading = false;
                    })
                } else {
                    this.$message.error('表单填写有误');
                    return false;
                }
            });
        },
        resetForm() {
            this.$refs.form.resetFields();
            this.form = this.$options.data().form;
            this.$emit('update:visible', false);
            this.$emit('refreshList');
        }
    }
}
</script>

<style scoped>

</style>